package com.chu.seviece.impl;

import com.chu.bean.People;
import com.chu.dao.PeopleDao;
import com.chu.seviece.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Service
public class PeopleServiceImpl implements PeopleService {
    @Autowired
    private PeopleDao peopleDao;
    @Override
    public People findById(int id) {
        return peopleDao.findOne(id);
    }

    @Override
    @Transactional
    public People savePeople(People people) {
        People save = peopleDao.save(people);
        return save;
    }

    @Override
    public People updatePeople(People people) {
        People save = peopleDao.save(people);
        return save;
    }

    @Override
    public List<People> findAll() {
        Iterable<People> list = peopleDao.findAll();
        Iterator<People> iterator = list.iterator();
        ArrayList arrayList = new ArrayList();
        while (iterator.hasNext()){
            People people = iterator.next();
            arrayList.add(people);
        }
        return arrayList;
    }

    @Override
    public List<People> findNameLike(String name) {
        List<People> list = peopleDao.findByNameLike(name);
        return list;
    }

    @Override
    public List<People> findByNameAndAddress(String name, String address) {
        return peopleDao.findByNameAndAddress(name,address);
    }

    @Override
    public List<People> findByIdBetween(int begin, int end) {
        return peopleDao.findByIdBetween(begin, end);
    }

    @Override
    public List<People> findByDateLessThanEqual(Date date) {
        return peopleDao.findByDateLessThanEqual(date);
    }

    @Override
    public List<People> findByAddressLike(String address) {
        return peopleDao.findByAddressLike(address);
    }

    @Override
    public List<People> findByIdIn(int[] id) {
        return peopleDao.findByIdIn(id);
    }

    @Override
    public Integer countByAddressIsNotLike(String address) {
        return peopleDao.countByAddressIsNotLike(address);
    }

    @Override
    public List<People> findAll(Sort sort) {
        return peopleDao.findAll(sort);
    }

    @Override
    public Page<People> findByIdIn(List list, Pageable pageable) {
        return peopleDao.findByIdIn(list, pageable);
    }


}
